using System;
using Microsoft.SPOT;
using GHIElectronics.NETMF.FEZ;
using InternetThermostat.Logging;
using InternetThermostat.Models;

namespace InternetThermostat.Views
{
    public class HomeView : View
    {
        private static int padding = 10;
        private static int buttonWidth = (ScreenWidth / 2) - (padding * 2);
        private static int buttonHeight = (ScreenHeight / 2) - (padding * 2);


        private static Point dashboardButton = new Point
        {
            X = padding,
            Y = padding
        };

        private static Point scheduleButton = new Point
        {
            X = (ScreenWidth / 2) + padding,
            Y = padding
        };

        private static Point emptyButton = new Point
        {
            X = padding,
            Y = (ScreenHeight / 2) + padding
        };

        private static Point debugButton = new Point
        {
            X = (ScreenWidth / 2) + padding,
            Y = (ScreenHeight / 2) + padding
        };


        public HomeView()
        {           
            // Add the four buttons
            Lcd.FillRectangle(dashboardButton.X, dashboardButton.Y, buttonWidth, buttonHeight, FEZ_Components.FEZTouch.Color.Gray);
            Lcd.FillRectangle(scheduleButton.X, scheduleButton.Y, buttonWidth, buttonHeight, FEZ_Components.FEZTouch.Color.Gray);
            Lcd.FillRectangle(emptyButton.X, emptyButton.Y, buttonWidth, buttonHeight, FEZ_Components.FEZTouch.Color.Gray);
            Lcd.FillRectangle(debugButton.X, debugButton.Y, buttonWidth, buttonHeight, FEZ_Components.FEZTouch.Color.Gray);

            Lcd.DrawString(dashboardButton.X + padding, dashboardButton.Y + padding, "Main Dashboard", FEZ_Components.FEZTouch.Color.Green, FEZ_Components.FEZTouch.Color.Black, AppSettings.Font);
            Lcd.DrawString(scheduleButton.X + padding, scheduleButton.Y + padding, "Weekly Schedule", FEZ_Components.FEZTouch.Color.Green, FEZ_Components.FEZTouch.Color.Black, AppSettings.Font);
            Lcd.DrawString(emptyButton.X + padding, emptyButton.Y + padding, "Empty Page", FEZ_Components.FEZTouch.Color.Green, FEZ_Components.FEZTouch.Color.Black, AppSettings.Font);
            Lcd.DrawString(debugButton.X + padding, debugButton.Y + padding, "Debug", FEZ_Components.FEZTouch.Color.Green, FEZ_Components.FEZTouch.Color.Black, AppSettings.Font);

            Lcd.TouchDownEvent += new FEZ_Components.FEZTouch.TouchEventHandler(lcd_TouchDownEvent);

        }
        

        void lcd_TouchDownEvent(int x, int y)
        {
            if (x > dashboardButton.X && x < dashboardButton.X + buttonWidth && y > dashboardButton.Y && y < dashboardButton.Y + buttonHeight)
            {
                Logger.Log("dashboardButton Pressed...");
                NavigateTo(typeof(DashboardView));
            }
            else if (x > scheduleButton.X && x < scheduleButton.X + buttonWidth && y > scheduleButton.Y && y < scheduleButton.Y + buttonHeight)
            {
                Logger.Log("scheduleButton Pressed...");
                NavigateTo(typeof(ScheduleView));
            }
            else if (x > emptyButton.X && x < emptyButton.X + buttonWidth && y > emptyButton.Y && y < emptyButton.Y + buttonHeight)
            {
                Logger.Log("emptyButton Pressed...");
                NavigateTo(typeof(EmptyView));

            }
            else if (x > debugButton.X && x < debugButton.X + buttonWidth && y > debugButton.Y && y < debugButton.Y + buttonHeight)
            {
                Logger.Log("debugButton Pressed...");
                NavigateTo(typeof(DebugView));

            }
        }



    }
}
